package com.situ.water_Invoice.mapper;

import com.situ.water_Invoice.pojo.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@Mapper
public interface IvOutinvoiceMapper extends BaseMapper<IvOutinvoice> {

    //多表连接查询(发票出库情况查询)
    @Select("select iv_outinvoice.id,iv_outinvoice.startNo,iv_outinvoice.endNo,iv_outinvoice.OutCounts s,iv_Invoice.used,iv_Invoice.invalid,iv_archive.arcounts,iv_outinvoice.outDate,sy_emp.empNmae,o.empNmae ename from iv_outinvoice left join iv_Invoice on iv_Invoice.OutID=iv_outinvoice.id left join sy_emp on iv_outinvoice.outempid=sy_emp.id left join sy_emp o on o.id=iv_outinvoice.EmpID left join IV_InInvoice on IV_InInvoice.id=IV_OutInvoice.InID left join iv_archive  on  IV_InInvoice.id=IV_Archive.InID")
    public List<FPCK> FPCK();

    //收费人员发票查询(多表)
    @Select("select SY_Emp.empNmae,iv_outinvoice.OutCounts,iv_Invoice.used,iv_Invoice.invalid,iv_archive.ArCounts from iv_outinvoice left join  SY_Emp on  iv_outinvoice.empid=SY_Emp.id  left join iv_Invoice on iv_Invoice.outid=iv_outinvoice.id  left join IV_InInvoice on iv_outinvoice.inid=IV_InInvoice.id left join iv_archive on iv_archive.inid=IV_InInvoice.id")
    public List<FPSF> FPSF();

    //查询StartNo 比较数据库和输入框的StartNo (发票开始号码)
    @Select("SELECT * FROM Iv_Outinvoice WHERE StartNo=#{value}")
    public IvOutinvoice queryId(String StartNo);

    //发票出库
    @Insert("INSERT INTO Iv_Outinvoice(EmpID,InID,StartNo,EndNo,OutCounts,OutEmpID) VALUES(#{EmpID},#{InID},#{StartNo},#{EndNo},#{OutCounts},#{OutEmpID})")
    public int addIvOutinvoice(IvOutinvoice ivOutinvoice);

    //查询刚刚出库的id
    @Select("SELECT * from Iv_Outinvoice ORDER BY ID DESC LIMIT 1")
    public IvIninvoice Ivinid();

}
